<template>
	<div class="">
		<div>
			<el-date-picker
				v-model="value2"
				type="daterange"
				align="right"
				unlink-panels
				range-separator="至"
				value-format="yyyy-MM-dd HH:mm:ss"
				start-placeholder="开始日期"
				end-placeholder="结束日期"
				:picker-options="pickerOptions"
			>
			</el-date-picker>
			<el-input id="patitentName" placeholder="请输入内容" v-model="searchName" style="width: 260px; margin-right: 20px; margin-left: 20px" clearable>
				<el-button slot="append" @click="searchDate" icon="el-icon-search"></el-button>
			</el-input>
		</div>

		<div style="margin-top: 20px">
			<el-table :data="tableData" border style="width: 100%" :row-style="{ height: '65px' }" :cell-style="{ height: '0px' }">
				<el-table-column fixed type="index" label="序号" width="100"></el-table-column>
				<el-table-column label="药品编号" prop="drug.dcard" width="130"></el-table-column>
				<el-table-column label="药品名称" prop="drug.dname" width="180"></el-table-column>
				<el-table-column label="药品品牌" prop="drug.dbrand" width="150"></el-table-column>
				<el-table-column label="药品售价" prop="drug.doutPrice" width="120"></el-table-column>
				<el-table-column label="数量" prop="drNumber" width="140"></el-table-column>
				<el-table-column label="开药时间" prop="drCreateTime" width="185"></el-table-column>
				<el-table-column label="患者名字" prop="patients.ptName" width="140"></el-table-column>
				<el-table-column label="主治医师" prop="sysUser.nickName" width="140"></el-table-column>
				<el-table-column label="诊断结果" prop="treatResult.trResult" width="140"></el-table-column>
				<el-table-column label="状态" prop="drStatus" width="100">
					<template slot-scope="scope">
						<label v-if="scope.row.drStatus == 'y'"> 开药 </label>
						<label v-if="scope.row.drStatus == 'n'"> 添药 </label>
					</template>
				</el-table-column>
				<el-table-column label="编辑" width="180px" fixed="right">
					<template slot-scope="scope">
						<el-button type="danger" @click="delRecord(scope.row)" size="small">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<div class="block" style="margin-left: 340px; margin-top: 30px">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page="current"
				:page-sizes="[6, 8, 10, 12]"
				:page-size="6"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
			>
			</el-pagination>
		</div>
	</div>
</template>

<script>
import axios from 'axios';

export default {
	data() {
		return {
			tableData: [],
			// name: '',
			size: 6,
			total: 0,
			current: 1,
			searchName: '',
			pickerOptions: {
				shortcuts: [
					{
						text: '最近一周',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
							picker.$emit('pick', [start, end]);
						},
					},
					{
						text: '最近一个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
							picker.$emit('pick', [start, end]);
						},
					},
					{
						text: '最近三个月',
						onClick(picker) {
							const end = new Date();
							const start = new Date();
							start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
							picker.$emit('pick', [start, end]);
						},
					},
				],
			},
			value1: '',
			value2: [],
			ks: '',
			js: '',
		};
	},
	components: {},
	methods: {
		searchDate() {
			console.log(this.value2)
			if(this.value2==null || this.value2.length==0){
				console.log('value2'+this.value2);
				var date=new Date();
				var yy=date.getFullYear();
				var MM=date.getMonth()+1;
				var dd=date.getDate();
				var hh=date.getHours();
				var mm=date.getMinutes();
				var ss=date.getSeconds();

				this.ks='1001-01-01 00:00:00';
				this.js=yy+'-'+MM+'-'+dd+' '+hh+':'+mm+':'+ss;
				// this.value2= ['1001-01-01 00:00:00',this.js];
				// let obj= JSON.parse(JSON.stringify(this.value2));
			}else{
				this.ks=this.value2[0];
				this.js=this.value2[1];
			}
			

			axios
				.get(
					'http://localhost/api/drug/record/findRecordAllByDate?size=' +
						this.size +
						'&current=' +
						this.current +
						'&name=' +
						this.searchName +
						'&ks=' +
						this.ks +
						'&js=' +
						this.js
				)
				.then((resp) => {
					this.tableData = resp.data.records;
					this.total = resp.data.total;
					this.current = resp.data.current;
				})
				.catch((error) => {
					console.log(error);
				});
		},
		handleSizeChange(val) {
			console.log(val);
			this.size = val;
			this.searchDate();
		},
		handleCurrentChange(val) {
			this.current = val;
			this.searchDate();
		},
		delRecord(val) {
			console.log(val);
			const drId = val.drId;
			axios
				.get('http://localhost/api/drug/record/delDrugRecord?drId=' + drId)
				.then((resp) => {
					this.$message({
						type: 'success',
						message: resp.data,
					});
					this.searchDate();
				})
				.catch((error) => {
					console.log(error);
				});
		},
	},
	mounted() {
		this.searchDate();
	},
};
</script>

<style  scoped>
</style>
